#ifndef __GAM_PROTOCOL_H__
#define __GAM_PROTOCOL_H__ 1

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
   MAXPATHLEN:

   Needed to check length of paths
*/
#ifndef MAXPATHLEN
#define MAXPATHLEN FILENAME_MAX
#endif

/**
   GAM_PROTO_VERSION:

   versionning at the protocol level
*/
#define GAM_PROTO_VERSION 1

/**
   GAMReqType:

   Type of FAM requests
*/
typedef enum {
  GAM_REQ_FILE = 1, /* monitoring a file */
  GAM_REQ_DIR = 2,  /* monitoring a directory */
  GAM_REQ_CANCEL = 3, /* cancelling a monitor */
  GAM_REQ_DEBUG = 4   /* debugging request */
} GAMReqType;

/**
   GAMReqOpts:

   Option for FAM requests
*/
typedef enum {
  GAM_OPT_NOEXISTS = 16 /* don't send Exists on directory monitoting */
} GAMReqOpts;

/**
   GAMPacket:

   Structure associated to a FAM survey request
   propagates from client to server
*/
typedef struct GAMPacket GAMPacket;
typedef GAMPacket *GAMPacketPtr;

struct GAMPacket {
  /* header */
  unsigned short len;   /* the total lenght of the request */
  unsigned short version; /* version of the protocol */
  unsigned short seq;   /* the sequence number */
  unsigned short type;  /* type of request GAMReqType | GAMReqOpts */
  unsigned short pathlen; /* the length of the path or filename */
  /* payload */
  char path[MAXPATHLEN];  /* the path to the file */
};

/**
   GAM_PACKET_HEADER_LEN:

   convenience macro to provide the length of the packet header.
*/
#define GAM_PACKET_HEADER_LEN (5 * (sizeof(unsigned short)))

#ifdef __cplusplus
}
#endif

#endif /* __GAMIN_FAM_H__ */

